﻿(function ($) {
    var opusTooltipSettings = {
        title: 'Tooltip',
        tip: '',
        my: 'bottom center',
        at: 'top center'
    };

    var methods = {
        init: function (options) {

            return this.each(function () {
                if (options) {
                    $.extend(opusTooltipSettings, options);
                }

                $(this).qtip({
                    content: {
                        text: opusTooltipSettings.tip,
                        title: {
                            text: opusTooltipSettings.title,
                            button: true
                        }
                    },
                    position: {
                        my: opusTooltipSettings.my,
                        at: opusTooltipSettings.at
                    },
                    show: {
                        event: 'focus'
                    },
                    hide: {
                        event: 'blur'
                    },
                    style: {
                        classes: 'ui-tooltip-rounded ui-tooltip-shadow',
                        widget: true
                    }
                });
            });
        },
        destroy: function () {
            return this.each(function () {
                $(this).unbind('.opusTooltip');
            });
        }
    };

    $.fn.opusTooltip = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.opusTooltip');
        }
    };
})(jQuery);
